console.log("addTaoBaoAddress js");

//一进来就先点击一下 修改默认地址
window.onload = function () {
    var targetName = document.getElementsByName("fullName")[1].value;

    var name = document.getElementsByClassName("next-table-cell-wrapper")[7].innerText;
    if (name != targetName) {
        document.getElementsByClassName("t-change")[0].click();
    }
};

//接受消息
chrome.runtime.onMessage.addListener(
    function (request, sender, sendResponse) {
        console.log(request.type);
        switch (request.type) {
            case"background_addAddress"://添加地址
                console.log(request.name);
                console.log(request.phone);
                console.log(request.address);
                var address=request.address;

                //点击确认按钮
                document.getElementsByTagName("button")[0].click();

                setTimeout(function () {
                    var buttons= document.getElementsByTagName("button");
                    if(buttons.length!=3){

                    }else{
                        document.getElementsByTagName("button")[1].click();
                    }
                }, 500);

                sendResponse({farewell: "success"});
                break;
        }
    }
);
